const express = require('express');
const router = express.Router();
const ModsPackAttach = require('../db/index').ModsPackAttach

router.post('/', (req, res, next) => {
	const id = req.body.id
	ModsPackAttach.create({
			title: `test${id}`
		},
		(err, result) => {
			if (err) return next(err)
			res.send('OK')
		})
})
router.get('/:id', (req, res, next) => {
	const id = req.params.id
	ModsPackAttach.find(id, (err, result) => {
		if (err) return next(err)
		res.send(result)
	})
})
router.get('/', (req, res, next) => {
	const params = {
		title: req.query.title
	}
	const page = {
		limit: req.query.limit,
		offset: req.query.offset
	}
	ModsPackAttach.page(params, page, (err, arr) => {
		if (err) return next(err)
		res.send(arr)
	})
})
router.delete('/:id', (req, res, next) => {
	const id = req.params.id
	ModsPackAttach.delete(id, (err) => {
		if (err) return next(err)
		res.send({
			message: 'delete'
		})
	})
})
module.exports = router;
